package com.yuanzi.base.oss;

import javax.annotation.PreDestroy;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.aliyun.oss.OSSClient;

/**
 * OSSClient配置
 * @author chengshx
 * @date 2017年7月18日
 *
 */
@Configuration
public class OSSConfig {
	
	private OSSClient client = null;
	
	@Bean(destroyMethod = "shutdown", name = "oSSClient")
	public OSSClient registOSSClient(@Value("${oss.accessKeyId}") String accessKeyId,
			@Value("${oss.secretAccessKey}") String secretAccessKey, 
			@Value("${oss.endpoint}") String endpoint) {
		client = new OSSClient(endpoint, accessKeyId, secretAccessKey);
		return client;
	}
	
	@PreDestroy
	public void shutdown() {
		if(client != null) {
			client.shutdown();
		}
	}
}
